home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-24 | 7.4 KB | 242 lines | [TEXT/KAHL] |
- // File "main.c" -
- // This source file is Copyright Matt Slot & Slot-Machines Ltd., © 1994
-
- #include <Processes.h>
- #include <Traps.h>
- #include "TextServices.h"
-
- #include "main.h"
- #include "windows.h"
- #include "prefs.h"
-
- // * ****************************************************************************** *
- // Global Vars
-
- extern GlobalsRec glob;
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void DoCreateWindow() {
- Point **prefLoc;
- Rect bounds, prefBounds;
-
- // Default location & size of window
- SetRect(&bounds, 60, 60, 160, 120);
-
- if (prefLoc = (Point **) GetPrefs('WLoc', 2)) {
- prefBounds = bounds;
- OffsetRect(&prefBounds, (*prefLoc)->h - prefBounds.left,
- (*prefLoc)->v - prefBounds.top);
-
- InsetRect(&prefBounds, 6, 6);
- if (RectInRgn(&prefBounds, GetGrayRgn())) {
- InsetRect(&prefBounds, -6, -6);
- bounds = prefBounds;
- }
- else {
- SetHandleSize((Handle) prefLoc, sizeof(**prefLoc));
- **prefLoc = topLeft(bounds);
- WritePrefs((Handle) prefLoc, 'WLoc', 2);
- }
- }
- else {
- prefLoc = (Point **) NewHandle(sizeof(**prefLoc));
- if (! prefLoc) return;
- **prefLoc = topLeft(bounds);
- WritePrefs((Handle) prefLoc, 'WLoc', 2);
- }
- DisposeHandle((Handle) prefLoc);
-
- NewServiceWindow(0, &bounds, "\p", 0, 2048, (WindowPtr) -1, -1,
- (ComponentInstance) kCurrentProcess, &glob.window);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
- // Insert your favorite code to initialize the window
-
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
-
- HiliteWindow(glob.window, -1);
- ShowHide(glob.window, -1);
- DoRevealWindow(-1);
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- void DoDisposeWindow() {
- Point **prefLoc;
- GrafPtr savePort;
-
- ShowHide(glob.window, 0);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
- // Insert your dispose code here
-
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
-
- // Just save the current window position
- if (prefLoc = (Point **) NewHandle(sizeof(**prefLoc))) {
- HLock((Handle) prefLoc);
- GetPort(&savePort);
- SetPort(glob.window);
- **prefLoc = topLeft(glob.window->portRect);
- LocalToGlobal(*prefLoc);
- SetPort(savePort);
-
- WritePrefs((Handle) prefLoc, 'WLoc', 2);
- DisposeHandle((Handle) prefLoc);
- }
-
- CloseServiceWindow(glob.window);
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- // This gets called after a click in the content region of the window
- // Use the global event record to localize and handle the click
- void DoClickWindow() {
- Point localPt;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(glob.window);
-
- localPt = glob.theEvent.where;
- GlobalToLocal(&localPt);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
- // Here is your click handling code
-
- InvertRect(&glob.window->portRect);
- while(StillDown());
- InvertRect(&glob.window->portRect);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
-
- SetPort(savePort);
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- // This gets called after a keydown while the window is on screen
- // Use the global event record to localize and handle the event.
- // NOTE: It is not recommended to intercept general keydowns!
- short DoKeydownWindow() {
- char theKey, theChar;
-
- theChar = glob.theEvent.message & charCodeMask;
- theKey = (glob.theEvent.message & keyCodeMask) >> 8;
-
- if ((glob.theEvent.modifiers & cmdKey) && (theKey == 0x35)) {
- glob.hidden = (glob.hidden) ? 0 : -1;
- DoCheckVisibility();
- return(0); // Pass it thru to other floaters!
- }
-
- return(0); // Return TRUE to say you have intercepted the Key Event
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- // This is your chance to make it zoom-able
- void DoZoomWindow(short zoomPart) {
- long ticks;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(glob.window);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
- // Do your Zoom Stuff
-
- InvertRect(&glob.window->portRect);
- Delay(7, &ticks);
- InvertRect(&glob.window->portRect);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
-
- SetPort(savePort);
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- // Simple Window update routine, just be sure to follow standard updateEvt etiquette
- void DoUpdateWindow() {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(glob.window);
- BeginUpdate(glob.window);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
- // General window drawing code
-
- MoveTo(glob.window->portRect.left + 2, glob.window->portRect.top + 2);
- LineTo(glob.window->portRect.right - 3, glob.window->portRect.bottom - 3);
- MoveTo(glob.window->portRect.right - 3, glob.window->portRect.top + 2);
- LineTo(glob.window->portRect.left + 2, glob.window->portRect.bottom - 3);
- LineTo(glob.window->portRect.right - 3, glob.window->portRect.bottom - 3);
- LineTo(glob.window->portRect.right - 3, glob.window->portRect.top + 2);
- LineTo(glob.window->portRect.left + 2, glob.window->portRect.top + 2);
- LineTo(glob.window->portRect.left + 2, glob.window->portRect.bottom - 3);
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
-
- EndUpdate(glob.window);
- SetPort(savePort);
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- // Indicates when the window is being shown or hidden
- void DoRevealWindow(short reveal) {
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
- // This function is yours if you need it
-
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
-
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- // Simple way to earn non-interrupt time
- void DoIdleWindow() {
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
- // This function is yours if you need it
-
-
- // ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• ••••• •••••
-
- }
-
- // * ****************************************************************************** *
- // * ****************************************************************************** *
-
- pascal WindowPtr SmartNewWindow(Ptr wStorage, Rect *bounds, StringPtr title, short visFlag,
- short wDefProcID, WindowPtr behind, short goAwayFlag, long refcon) {
- long response;
- WindowPtr theWindow;
- NewWindowProc newWinProc;
-
- newWinProc = (void *) glob.saveNewWindow;
-
- theWindow = (glob.hasColorQD) ? (NewCWindow(wStorage, bounds, title, visFlag,
- wDefProcID, behind, goAwayFlag, refcon)) : ((*newWinProc)(wStorage, bounds,
- title, visFlag, wDefProcID, behind, goAwayFlag, refcon));
-
- return(theWindow);
- }
-
-